package com.power.using.mybomb.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.power.using.mybomb.MainActivity;
import com.power.using.mybomb.R;
import com.power.using.mybomb.base.BaseActivity;
import com.power.using.mybomb.model.UserModel;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.LogInListener;

/**
 * Created by 聪明一只哈 on 2020/3/19.
 * Time: 2020/3/19  16:01
 */
public class LoginActivity extends BaseActivity {

    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.et_username)
    EditText etUsername;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.tv_register)
    TextView tvRegister;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

    }


    @OnClick({R.id.btn_login, R.id.tv_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:

                UserModel.getInstance().login(etUsername.getText().toString(), etPassword.getText().toString(), new LogInListener() {
                    @Override
                    public void done(Object o, BmobException e) {
                        if(e==null){
                            startActivity(MainActivity.class,null,true);
                        }else{
                            toast(e.getMessage() + "(" + e.getErrorCode() + ")");
                        }
                    }

                });

                break;
            case R.id.tv_register:

                startActivity(RegisterActivity.class,null,false);

                break;
        }
    }
}
